<?php

namespace App\Http\Requests\Admin;

use Illuminate\Foundation\Http\FormRequest;

class DishRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
     */
    public function rules(): array
    {
        return [
            'name' => 'required|string|max:100',
            'description' => 'nullable|string',
            'category_id' => 'required|exists:categories,id',
            'tags' => 'nullable|string',
            'flavors' => 'nullable|string',
            'cooking_time' => 'integer|min:0',
            'sort_order' => 'integer|min:0',
            'is_featured' => 'boolean'
        ];
    }

    /**
     * Get custom messages for validator errors.
     */
    public function messages(): array
    {
        return [
            'name.required' => '菜品名称不能为空',
            'name.max' => '菜品名称不能超过100个字符',
            'category_id.required' => '请选择分类',
            'category_id.exists' => '选择的分类不存在',
            'cooking_time.integer' => '制作时间必须是整数',
            'cooking_time.min' => '制作时间不能小于0',
            'sort_order.integer' => '排序必须是整数',
            'sort_order.min' => '排序不能小于0',
            'is_featured.boolean' => '推荐状态必须是布尔值',
            'tags.string' => '标签必须是字符串格式',
            'flavors.string' => '口味必须是字符串格式',
        ];
    }
}
